import time

from selenium.webdriver.common.by import By
from Page.Page import Page

class Page1(Page):
    home_loc=(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a')
    def home_click(self):
        self.click(self.home_loc)
    search_loc=(By.XPATH,'//*[@id="searchForm"]/div[1]/input')
    def search_input(self):
        self.send_keys(self.search_loc,'手机')
    def enter(self):
        self.Enter(self.search_loc)
    goods_loc=(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/ul/li[2]/div[1]/em/a')
    def goods_click(self):
        self.click(self.goods_loc)
    yq1_loc=(By.XPATH,'//*[@id="sell-price-box"]')
    def yq1(self):
        return self.text(self.yq1_loc)
    goods_nums=(By.XPATH,'//*[@id="store_nums"]')
    def up_num(self):
        self.clear(self.goods_nums)
        self.send_keys(self.goods_nums,2)
    buy_loc=(By.ID,'buy-cart')
    def buy(self):
        self.click(self.buy_loc)
    address_loc=(By.ID,'address-712')
    def adds(self):
        self.click(self.address_loc)
    order_loc=(By.XPATH,'//*[@id="order-button"]')
    def order(self):
        self.click(self.order_loc)
    yq2_loc=(By.XPATH,'/html/body/div[4]/div[3]/span')
    def yq2(self):
        return self.text(self.yq2_loc)

    def luoji_02_search(self):
        # 登录
        self.luoji_01_login()
        # 点击首页
        self.home_click()
        # 搜索框输入
        self.search_input()
        # 回车
        self.enter()
        # 选择商品
        self.goods_click()
        print(self.yq1())
        # 修改商品数量
        self.up_num()
        # 点击立即购买
        self.buy()
        # 选择收货地址
        self.adds()
        # 点击下一步
        self.order()
        print(self.yq2())
        assert self.yq2() == "您的订单支付成功"